<template>
  <el-card header="统计信息" class="form-section sidebar-card">
    <el-row :gutter="20">
      <el-col :span="12">
        <div class="stat-item">
          <div class="stat-label">跟进次数</div>
          <div class="stat-value">{{ data.followup_count || 0 }}</div>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="stat-item">
          <div class="stat-label">最后跟进</div>
          <div class="stat-value is-time">{{ formatTime(data.last_followup_time) }}</div>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="12">
        <div class="stat-item">
          <div class="stat-label">订单数</div>
          <div class="stat-value">{{ data.order_count || 0 }}</div>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="stat-item">
          <div class="stat-label">订单金额</div>
          <div class="stat-value">¥{{ Number(data.total_order_amount || 0).toFixed(2) }}</div>
        </div>
      </el-col>
    </el-row>
  </el-card>
</template>

<script setup lang="ts">
  import { defineProps } from 'vue'

  const props = defineProps({
    data: {
      type: Object,
      default: () => ({}),
    },
  })

  const formatTime = (timestamp: number) => {
    if (!timestamp) return '-'
    const date = new Date(timestamp * 1000)
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    return `${month}-${day}`
  }
</script>

<style scoped>
  .stat-item {
    text-align: center;
    padding: 15px;
    border: 1px solid #e4e7ed;
    border-radius: 4px;
    margin-bottom: 10px;
    height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .stat-label {
    font-size: 14px;
    color: #909399;
    margin-bottom: 8px;
  }

  .stat-value {
    font-size: 20px;
    font-weight: bold;
    color: #303133;
  }

  .stat-value.is-time {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>
